using System.IO;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;

namespace SceneManager.Pipeline
{
	/// <summary>
	/// This class will be instantiated by the XNA Framework Content Pipeline
	/// to write the specified data type into binary .xnb format.
	///
	/// This should be part of a Content Pipeline Extension Library project.
	/// </summary>
	[ContentTypeWriter]
	public class XElementWriter : ContentTypeWriter<XElement>
	{
		protected override void Write(ContentWriter output, XElement value)
		{
			var stream = new MemoryStream();
			var writer = new StreamWriter(stream);
			value.Save(writer);

			output.Write(stream.Length);
			output.Write(stream.ToArray());

			stream.Close();
		}

		public override string GetRuntimeReader(TargetPlatform targetPlatform)
		{
			return "SceneManager.XElementReader, SceneManager";
		}
	}
}